<script setup>
import { useUserStore } from '@/stores'
import { userUpdateInfoService } from '@/api/user'
import { ref } from 'vue'
const {
  user: { userName, id, account, roleName, roleDescription }
} = useUserStore()
const userStore = useUserStore()
const formRef = ref()
const userInfo = ref({ userName, id, account, roleName, roleDescription })
const onSubmit = async () => {
  await formRef.value.validate()
  await userUpdateInfoService(userInfo.value)
  await userStore.getUser()
  ElMessage.success('修改成功')
}
const rules = {
  userName: [
    { required: true, message: '请输入用户昵称', trigger: 'blur' },
    {
      pattern: /^\S{2,10}$/,
      message: '昵称必须是2-10位的非空字符串',
      trigger: 'blur'
    }
  ]
}
</script>

<template>
  <page-container title="基本资料">
    <el-row>
      <el-col :span="12">
        <el-form :model="userInfo" :rules="rules" ref="formRef" label-width="100px" size="large">
          <el-form-item label="登录账号">
            <el-input v-model="userInfo.account" disabled></el-input>
          </el-form-item>
          <el-form-item label="用户权限" prop="roleName">
            <el-input v-model="userInfo.roleName" disabled></el-input>
          </el-form-item>
          <el-form-item label="权限描述" prop="roleDescription">
            <el-input v-model="userInfo.roleDescription" disabled></el-input>
          </el-form-item>
          <el-form-item label="用户昵称" prop="userName">
            <el-input v-model="userInfo.userName"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">提交修改</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </page-container>
</template>
